package com.hd123.rumba.runtime;

import java.io.ByteArrayInputStream;
import java.util.Iterator;

import org.apache.log4j.Logger;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

public class License {
  public static String name;
  public static String productData;
  public static String user;
  public static String address;
  public static String contactor;
  public static String telephone;
  public static String email;
  public static String expiration;
  public static String EXPIRATION_VALUE_NEVER = "never";
  public static String feature;
  public static String checksum;

  public static void setLicense(String xmlString) throws Exception {
    org.dom4j.Document doc = new SAXReader().read(new ByteArrayInputStream(
        ("<?xml version=\"1.0\" encoding=\"gb2312\"?>" + xmlString).getBytes()));
    Iterator nodes = doc.getRootElement().elementIterator();
    while (nodes.hasNext()) {
      Element node = (Element) nodes.next();
      try {
        License.class.getDeclaredField(node.getName()).set(null, node.getTextTrim());
      } catch (Exception e) {
        Logger.getLogger(License.class).error(
            "设置许可证值错误: " + node.getName() + "=" + node.getTextTrim() + ": " + e.getMessage());
      }
    }
  }
}
